import java.io.*;
/**
 *
 * @author Alex
 */
public class TestLinkedList {

    public static void main(String[] args) {
        LinkedList l = new LinkedList();
        System.out.println("The contents of the LinkedList: " + l.toString());

        try{
            // Open the file
            FileInputStream fstream = new FileInputStream("/Users/Alex/NetBeansProjects/Opdracht1/src/input2");
            // Get the object of DataInputStream
            DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            String strLine;
            //Read File Line By Line
            while ((strLine = br.readLine()) != null){
                //add the contents of the textfile to the list
                l.addFirst(Integer.parseInt(strLine));
            }
            //Close the input stream
            in.close();
        }
        catch (Exception e){//Catch exception if any
              System.err.println("Error: " + e.getMessage());
        }

        System.out.println("The contents of the LinkedList: " + l.toString());
        System.out.println();

        System.out.println("Position of number  4: " + l.indexOf(4));
        System.out.println("Position of number 20: " + l.indexOf(20));
        System.out.println();

        System.out.println("Number 456 is added to the rear");
        l.addLast(456);
        System.out.println("The contents of the LinkedList:");
        System.out.println(l.toString() + "\n");

        l.removeFirst();
        l.removeLast();
        System.out.println("The first and last number were removed");
        System.out.println("The contents of the LinkedList:");
        System.out.println(l.toString() + "\n");

        System.out.println("The contents of the LinkedList after reversal:");
        LinkedList reverse = l.reverse();
        System.out.println(reverse.toString());

    }

}